package com.eve.eplus.main.logic;

import com.eve.eplus.common.app.BaseApplication;
import com.eve.eplus.common.app.Configuration;
import com.eve.eplus.common.app.Constants;
import com.eve.eplus.common.app.SettingConstants;
import com.eve.eplus.common.tools.ConfigurationTools;

/**
 * 设置项工具，用于设置内容的读取和保存
 * 
 * @author norsie
 * 
 */
public class SettingUtility
{
    /**
     * 默认设置
     */
    public static void putDefaultSetting()
    {
        setImgLoadTypeSetting(Configuration.DEFAULT_IMG_LOADTYPE_SETTING);
        setTextFontSizeSetting(Configuration.DEFAULT_TEXT_FONTSIZE_SETTING);
        setAutoReflashSetting(Configuration.DEFAULT_AUTOREFLASH_SETTING);
        setWelcomeSetting(Configuration.DEFAULT_WELCOME_SETTING);
        setCameraSaveSetting(Configuration.DEFAULT_CAMERA_SAVE_SETTING);
    }

    private static void putSetting(String TAG, int value)
    {
        ConfigurationTools.getInstance(BaseApplication.mAppContext).putInt(TAG,
                value);
    }

    private static int getSetting(String TAG)
    {
        return ConfigurationTools.getInstance(BaseApplication.mAppContext).getInt(
                TAG);
    }

    /**
     * 图片设置
     */
    public static void setImgLoadTypeSetting(int value)
    {
        putSetting(SettingConstants.IMG_LOADTYPE, value);
    }

    /**
     * 返回图片设置
     */
    public static int getImgLoadTypeSetting(boolean deal)
    {
        if(deal)
            if (getSetting(SettingConstants.IMG_LOADTYPE) == SettingConstants.IMG_LOADTYPE_AUTO)
                if (BaseApplication.mNetStyleCode == Constants.NETWORK_TYPE_WIFI)
                    return SettingConstants.IMG_LOADTYPE_BMIDDLE;
                else
                    return SettingConstants.IMG_LOADTYPE_THUMBNAIL;
            else
                return getSetting(SettingConstants.IMG_LOADTYPE);
        else
            return getSetting(SettingConstants.IMG_LOADTYPE);
    }

    /**
     * 文字设置
     */
    public static void setTextFontSizeSetting(int value)
    {
        putSetting(SettingConstants.TEXT_FONTSIZE, value);
    }

    /**
     * 返回文字设置
     */
    public static int getTextFontSizeSetting()
    {
        return getSetting(SettingConstants.TEXT_FONTSIZE);
    }

    /**
     * 自动刷新设置
     */
    public static void setAutoReflashSetting(int value)
    {
        putSetting(SettingConstants.AUTOREFLASH, value);
    }

    /**
     * 返回自动刷新设置
     */
    public static int getAutoReflashSetting(boolean deal)
    {
        if(deal)
            if (getSetting(SettingConstants.AUTOREFLASH) == SettingConstants.AUTOREFLASH_AUTO)
                if (BaseApplication.mNetStyleCode == Constants.NETWORK_TYPE_WIFI)
                    return SettingConstants.AUTOREFLASH_TRUE;
                else
                    return SettingConstants.AUTOREFLASH_FALSE;
            else
                return getSetting(SettingConstants.AUTOREFLASH);
        else
            return getSetting(SettingConstants.AUTOREFLASH);
    }

    /**
     * 拍摄设置
     */
    public static void setCameraSaveSetting(int value)
    {
        putSetting(SettingConstants.CAMERA_SAVE, value);
    }

    /**
     * 返回拍摄设置
     */
    public static int getCameraSaveSetting()
    {
        return getSetting(SettingConstants.CAMERA_SAVE);
    }

    /**
     * 欢迎页面设置
     */
    public static void setWelcomeSetting(int value)
    {
        putSetting(SettingConstants.WELCOME, value);
    }

    /**
     * 返回欢迎页面设置
     */
    public static int getWelcomeSetting()
    {
        return getSetting(SettingConstants.WELCOME);
    }
}
